package com.example.medicalrecord.AggregationModule.work.controller;

import com.example.medicalrecord.AggregationModule.work.pojo.dto.ApplicationParam;
import com.example.medicalrecord.AggregationModule.work.pojo.dto.ApplicationQuery;
import com.example.medicalrecord.AggregationModule.work.pojo.vo.ApplicationVO;
import com.example.medicalrecord.AggregationModule.work.service.ApplicationService;
import com.example.medicalrecord.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "员工请假模块")
@RestController
@RequestMapping("/v1/application/")
public class ApplicationController {

    @Autowired
    ApplicationService applicationService;

    @ApiOperation(value = "搜索请假功能")
    @GetMapping("select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
        log.debug("搜索请假:applicationQuery={}",applicationQuery);
        List<ApplicationVO> applicationVOList = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(applicationVOList);
    }

    @ApiOperation(value = "修改申请状态")
    @PostMapping("updateStatus")
    public JsonResult updateStatus(ApplicationParam applicationParam){
        log.debug("修改申请状态:applicationParam={}",applicationParam);
        applicationService.updateStatus(applicationParam);
        return JsonResult.ok();
    }

    @ApiOperation(value = "删除请假申请")
    @PostMapping("delete/{id}")
    public JsonResult deleteApplication(@PathVariable Long id){
        log.debug("删除请假申请:id={}",id);
        applicationService.deleteApplication(id);
        return JsonResult.ok();
    }

}
